package main.java.ensao.cryptography.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import main.java.ensao.cryptography.elgamalmodule.ELGAMALEncryptionListner;
import main.java.ensao.cryptography.elgamalmodule.ELGAMALGeneratingKeysListner;
import main.java.ensao.cryptography.elgamalmodule.ELGAMALGeneratingSessionKeyListner;
import main.java.ensao.cryptography.elgamalmodule.ElGAMALDecryptionListner;
import main.java.ensao.cryptography.elgamalmodule.InitializeListner;



public class ELGAMALPane extends JPanel {
	
	JTextField textField_publ_p;
	JTextField textField_publ_g;
	JTextField textField_publ_y;
	JTextField textField_priv_k;
	
	JTextField textField_publ_alpha;
	JTextField textField_publ_K;
	JTextField textField_publ_Kalpha;
	
	JTextField textField_clair;
	JTextField textField_chiffré;
	
	JLabel gen_keys;
	JLabel chiff_dechiff;
	
	JLabel label_y;
	JLabel label_p;
	JLabel label_g;
	JLabel label_kB;

	JLabel label_alpha;
	JLabel label_k;
	JLabel label_kalpha;
	
	
	JLabel label_clair;
	JLabel label_chiffré;

	public ELGAMALPane() {
		
		this.init();
		
	}

	public void init() {

		this.setLayout(new GridBagLayout());
		
		GridBagConstraints gbc = new GridBagConstraints();

/**************************************************Labels OF Titles**************************************************/
		
		JLabel label = new JLabel("Saissisez pB et gB : ");
		gen_keys = new JLabel("Génération de la clé de session ");
		chiff_dechiff = new JLabel("Chiffrement/Déchiffrement ");
		
		
/*************************************************Labels of TextFields************************************************/
		
		label_p = new JLabel(" pB :");
		label_g = new JLabel(" gB :");
		label_kB = new JLabel("KB :");
		label_y = new JLabel("b :");
		
		label_k = new JLabel("K :");
		label_alpha = new JLabel("alpha :");
		label_kalpha=new JLabel("Kalpha");
		
		label_clair=new JLabel("clair");
		label_chiffré=new JLabel("chiffré");
		
/***************************************************TextFields********************************************************/	
		textField_publ_p = new JTextField(10);
		textField_publ_g = new JTextField(10);
		textField_publ_y = new JTextField(10);
		textField_publ_y.enable(false);
		textField_priv_k = new JTextField(10);
		textField_priv_k.enable(false);
		
		textField_publ_Kalpha=new JTextField(8);
		textField_publ_alpha = new JTextField(10);
		textField_publ_K = new JTextField(10);
		textField_publ_K.enable(false);
		
		textField_clair=new JTextField(9);
		textField_chiffré=new JTextField(9);
/********************************************Buttons and their Listeners***********************************************/
		JButton sign = new JButton("générer les clés");
		sign.addActionListener(new ELGAMALGeneratingKeysListner());

		JButton generate_session_key = new JButton("générer la clé de session");
		generate_session_key.addActionListener(new ELGAMALGeneratingSessionKeyListner());
		
		JButton Chiffrer_Button = new JButton("Chiffrer");
		Chiffrer_Button.addActionListener(new ELGAMALEncryptionListner());
		
		JButton Dechiffrer_Button = new JButton("Déchiffrer");
		Dechiffrer_Button.addActionListener(new ElGAMALDecryptionListner());
		
		JButton Initialize_Button = new JButton("Initialiser");
		Initialize_Button.addActionListener(new InitializeListner());
		
		
/***************************************Nouvelle Ligne****************************************************************/	
		
		gbc.insets = new Insets(10, 10, 10, 10);
		this.add(label, gbc);
	
/*****************************************************Nouvelle ligne**************************************************/		
		gbc.gridy = 2;
		gbc.gridx = 0; 

		                         /*****************************************************/

		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
        gbc.fill = GridBagConstraints.NONE;
		                      
        
                                 /*****************************************************/

		JPanel p = new JPanel();
		p.add(label_p);
		p.add(textField_publ_p);
		gbc.insets = new Insets(10, 10, 10, 10);
		this.add(p, gbc);
		
		gbc.gridx = 4;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 3, 0, 10);
		JPanel g = new JPanel();
		g.add(label_g);
		g.add(textField_publ_g);
		this.add(g, gbc);
		
		gbc.gridx = 5;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(10, 10, 10, 10);
		JPanel signPanel = new JPanel();
		signPanel.add(sign);
		this.add(sign, gbc);

/*************************************************************Nouvelle Ligne************************************************/
		
		gbc.gridy = 3; 
		gbc.gridx = 0; 
                                 /*********************************************************/
		gbc.gridwidth = 2;
		gbc.gridheight = 1;
		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		
		                         /*********************************************************/
		JPanel k = new JPanel();
		k.add(label_kB);
		k.add(textField_priv_k);
		gbc.insets = new Insets(10, 10, 10, 10);
		this.add(k, gbc);

		
		gbc.gridx = 3;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 3, 0, 10);
		JPanel y = new JPanel();
		y.add(label_y);
		y.add(textField_publ_y);
		this.add(y, gbc);

/********************************************Nouvelle ligne*****************************************************************/	
	
		gbc.gridy = 4; 
		gbc.gridx = 0; 
		
		                         /*********************************************************/
		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10, 10, 10, 10);
		
		                        /*********************************************************/
		this.add(gen_keys, gbc);
/*************************************************Nouvelle Ligne************************************************************/
		
		gbc.gridy = 5; 
		gbc.gridx = 0; 
		
		                        /*********************************************************/
		
		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10, 10, 10, 10);
	
		                        /*********************************************************/
		JPanel r = new JPanel();
		r.add(label_alpha);
		r.add(textField_publ_alpha);
		this.add(r, gbc);
		
		
		gbc.gridx = 3;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 3, 0, 10);
		JPanel s = new JPanel();
		s.add(label_k);
		s.add(textField_publ_K);
		this.add(s, gbc);

		gbc.gridx = 5;
		gbc.weightx = 0.;
		gbc.insets = new Insets(12, 0, 0, 0);
		this.add(generate_session_key, gbc);

/*************************************************Nouvelle Ligne************************************************************/
		
		gbc.gridy = 6; 
		gbc.gridx = 0; 
		             
		                     /*********************************************************/
		
		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10, 10, 10, 10);
		
		                    /*********************************************************/
		this.add(chiff_dechiff, gbc);
	
	
		
/*************************************************Nouvelle Ligne************************************************************/

		gbc.gridy = 7; 
		gbc.gridx = 0; 
		
                                /*********************************************************/


		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10, 10, 10, 10);
	
		
                                /*********************************************************/

		JPanel w = new JPanel();
		w.add(label_clair);
		w.add(textField_clair);
		this.add(w, gbc);
		                       


		gbc.gridx = 3;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 3, 0, 10);
		JPanel h = new JPanel();
		h.add(label_chiffré);
		h.add(textField_chiffré);
		this.add(h, gbc);
		
		
		
		gbc.gridx = 5;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 3, 0, 10);
		JPanel Kaplha_panel = new JPanel();
		Kaplha_panel.add(label_kalpha);
		Kaplha_panel.add(textField_publ_Kalpha);
		this.add(Kaplha_panel, gbc);
		
/****************************************************************************************************************************/
		gbc.gridy = 8; 
		gbc.gridx = 0; 
		
                                /*********************************************************/


		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10, 10, 10, 10);
	
		
                                /*********************************************************/

		
	
		
		this.add(Chiffrer_Button, gbc);              


		gbc.gridx = 3;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 0, 0,10);
		this.add(Dechiffrer_Button, gbc);
		
		gbc.gridx = 5;
		gbc.weightx = 0.; 
		gbc.insets = new Insets(0, 0, 0,10);
		this.add(Initialize_Button, gbc);
		
	

	}
}
